import { apiUserGetLoginUser, purtbSelectAll, purtbSelectPurtb } from '@/api/url/salesOrderManagement';
import router from '@/router';
import { EFTimeFormatConversion, formatDate, isNullPm, spaceTime } from '@/utils/baseMethods';
import { PURTBCHANGE } from '@/utils/EFCODE';
import { onMounted, reactive, watch } from 'vue';

import notification from '@arco-design/web-vue/es/notification';
import XEClipboard from 'xe-clipboard';
import { VXETable } from 'vxe-table';
import { dayjs } from '@arco-design/web-vue/es/_utils/date';

export default function importConfig() {
  const base = reactive<any>({
    tabelList: null,
    tableRef: null,
  });

  const getTable = () => {
    const relt = JSON.parse(localStorage.getItem('excelPreviewData'));
    base.tabelList = relt[0];
  };

  /**
   * @exports menuConfig 表单配置器
   */
  const menuConfig = reactive<any>({
    className: 'my-menus',
    body: {
      options: [
        [{ code: 'copy', name: '复制', prefixIcon: 'vxe-icon-copy', className: 'my-copy-item' }],
        [{ code: 'viewDetails', name: '查看详情', prefixIcon: 'vxe-icon-success-circle-fill', className: 'my-copy-item' }],
      ],
    },
  });
  /**
   * @exports contextMenuBodyClickEvent 表单操作格式
   * @param param0
   */
  const contextMenuBodyClickEvent = ({ menu, row, column }) => {
    switch (menu.code) {
      case 'viewDetails':
        purchaseRequisitionDetails(row);
        break;
      case 'copy':
        // 示例
        if (row && column) {
          console.log(row, column);
          if (XEClipboard.copy(row[column.field])) {
            VXETable.modal.message({ content: '已复制到剪贴板！', status: 'success' });
          }
        }
        break;
      default:
        console.log(`点击了 ${menu.name} 选项`, row, column, row[column.field]);
    }
  };

  /**
   * @exports purchaseRequisitionDetails 请购单详情
   */
  const purchaseRequisitionDetails = (param) => {
    // const steam = {
    //   tb001: param.requisitionType,
    //   tb002: param.requisitionNo,
    //   tb003: param.requisitionNumber,
    // };
    // purtbSelectPurtb(steam).then((res: any) => {
    //   if (res.code == '200') {
    //     base.desData = PURTBCHANGE(res.data);
    //     base.visible = true;
    //   }
    // });
  };

  //返回上一页
  const goBack = () => {
    localStorage.removeItem('excelPreviewData');
    router.go(-1);
  };

  onMounted(() => {
    getTable();
  });

  return {
    base,
    menuConfig,
    contextMenuBodyClickEvent,
    goBack,
  };
}
